package org.example.utils;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.example.common.HygResponse;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author liyishan
 * @date 2023/4/18 14:35
 */
@Slf4j
public class WriterUtil {
    private WriterUtil() {
    }

    /**
     * 返回json格式的数据
     *
     * @param response
     * @param hygResponse
     * @throws IOException
     */
    public static void writerJson(HttpServletResponse response, HygResponse hygResponse) throws IOException {
        response.setContentType("application/json; charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.write(JSON.toJSONString(hygResponse));
        writer.flush();
        writer.close();
    }
}
